import matplotlib.pyplot as plt
import numpy as np

from rootPath import project_path

species = ("1", "2", "3", "4","5")
penguin_means = {
    'MR':       (3.4608, 1.4316, 0.6124, 0.2908, 0.1748),
    'WS':       (3.3570, 1.3292, 0.5269, 0.2299, 0.1275),
    'RS+CNDSR': (1.2931, 0.1735, 0.0264, 0.0057, 0.0018),
    'WS+CNDSR': (1.1454, 0.1440, 0.0186, 0.0037, 0.0015),
}

x = np.arange(len(species))  # the label locations
width = 0.10  # the width of the bars
multiplier = 0

fig, ax = plt.subplots(figsize=(12, 6), layout='constrained')

for attribute, measurement in penguin_means.items():
    offset = width * multiplier
    rects = ax.bar(x + offset, measurement, width, label=attribute)
    # ax.bar_label(rects, padding=3, fontsize=6)  # 设置字体大小为12
    multiplier += 1


size = 20
ax.set_ylabel('acc gap', fontsize=size)
ax.set_xlabel('gradient combination number', fontsize=size)
ax.tick_params(axis='y', labelsize=size)
ax.set_xticks(x + width * (len(penguin_means) - 1) / 2, species, fontsize=size)
ax.legend(loc='upper right', ncols=3, fontsize=size)
ax.set_ylim(0, 3.5)

# 保存图形到文件，确保文件名包含 .png 扩展名
plt.savefig(project_path + '/experiment/imgs/gap_acc.png', dpi=300, bbox_inches='tight')
plt.show()
